#ifndef TEXTURE_2D
#define TEXTURE_2D

#include <iosfwd>
#include <fstream>
#include "../core/os/string.h"
#include "../core/math/vector2d.h"
#include "../core/math/vector3d.h"
//#include "../core/math/quaternion.h"
#include "pixel.h"

#include "format/raw.h"
#include "format/bmp.h"
#include "format/jpg.h"
#include "format/png.h"
#include "format/tga.h"

namespace sleek
{
    namespace core
    {
        namespace device
        {
            class Device;
        }
    }
    namespace texture
    {
        enum TextureFormat
        {
            TXFMT_LUMINANCE = 1,
            TXFMT_LUMINANCE_ALPHA = 2,
            TXFMT_RGB  = 3,
            TXFMT_RGBA = 4
        };
        class texture
        {
            public:
                texture(core::math::vector2du s, TextureFormat a = TXFMT_RGBA);
                virtual ~texture();

                virtual void make(core::math::vector2du,pixel);
                virtual void setPixel(core::math::vector2du,pixel);

                virtual core::math::vector2du getOriginalSize();
                virtual pixel getPixel(core::math::vector2du);
                virtual TextureFormat getFormat();

                virtual texture *clone();
                virtual texture *monochrome();
                virtual GLuint glTexture();
                virtual void updateGl();

                void flipVertical();
                void flipHorizotal();
                void invertColor();
            protected:
                texture(){}
                void GenerateGlTexture();
                void CreateGlTexture();
                void FreeGlTexture();
            private:
                GLuint gl;
                bool isloaded;
                core::u8 *buffer;
                core::os::stringc filename;
                core::math::vector2du original;
                TextureFormat fmt;

                friend class draw;
                friend class core::device::Device;

                friend texture* LoadTextureFromRaw(core::math::vector2du, core::u32 format, void*);
                friend texture* LoadTextureFromBmp(core::os::stringc);
                friend texture* LoadTextureFromPng(core::os::stringc);
                friend texture* LoadTextureFromJpg(core::os::stringc);
                friend texture* LoadTextureFromTga(core::os::stringc);

                friend bool WriteTextureToBmp(texture*,core::os::stringc);
                friend bool WriteTextureToPng(texture*,core::os::stringc);
                friend bool WriteTextureToJpg(texture*,core::os::stringc);
                friend bool WriteTextureToTga(texture*,core::os::stringc);
        };
    }
}

#endif
